package com.indexingsystem.boss.filter;


import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.context.annotation.Scope;

import com.indexingsystem.boss.common.Constants;
import com.indexingsystem.system.service.IPusersService;

/**
 * <p>User: admin
 */
@Scope(value = "prototype")
public class SysUserFilter extends PathMatchingFilter {

	@Resource
	private IPusersService iPusersService;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {

        String username = (String)SecurityUtils.getSubject().getPrincipal();
        request.setAttribute(Constants.CURRENT_USER, iPusersService.getUserInfoByUserName(username));
        return true;
    }
}
